package com.server.llh.llhserverwork.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.bean.AddressAll;

import java.util.List;

/**
 * Created by ZTF on 2017-05-23.
 */

public class SpinnerAdapter extends BaseAdapter {
    List<AddressAll> addressAllList;
    Context context;
    public SpinnerAdapter(Context context, List<AddressAll> addressAllList){
        this.context=context;
        this.addressAllList=addressAllList;
    }
    @Override
    public int getCount() {
        if (addressAllList==null&&addressAllList.size()==0){
            return 0;
        }
        return addressAllList.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SpinnerProHolder spinnerProHolder=null;
        if (convertView==null){
            spinnerProHolder=new SpinnerProHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.llh_spinner_item, null);
            spinnerProHolder.tvName= (TextView) convertView.findViewById(R.id.sp_name);
            convertView.setTag(spinnerProHolder);
        }else{
            spinnerProHolder = (SpinnerProHolder) convertView.getTag();
        }
        AddressAll addressAll=   addressAllList.get(position);
        spinnerProHolder.tvName.setText( addressAll.getOptName());
        return convertView;
    }
    public class SpinnerProHolder  {
        TextView tvName;
    }
}
